package com.aijk.web.admin.controller.openapi;

import com.aijk.ehm.api.SysAppVersionApi;
import com.aijk.ehm.model.SysAppVersion;
import com.aijk.ehm.model.qo.SysAppVersionQo;
import com.aijk.web.admin.controller.openapi.entity.ApiResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;
import java.util.List;

@Component
@Controller
public class AppVersionController extends ApiBaseController {

    private static final Logger logger = LoggerFactory.getLogger(AppVersionController.class);


    @Autowired
    private SysAppVersionApi sysAppVersionApi;

    /**
     * 版本更新
     * @param
     * @return
     */
    @RequestMapping(path = "app/version/get", method = {RequestMethod.POST, RequestMethod.GET})
    @ResponseBody
    public Object feedback(@Valid SysAppVersionQo sysAppVersionQo) {
        ApiResponse response = new ApiResponse();
        sysAppVersionQo.setSortway("version desc, build desc");

        List<SysAppVersion> sysAppVersions = sysAppVersionApi.list(sysAppVersionQo);
        if (sysAppVersions.size() >0){
            response = new ApiResponse();
            response.setData(sysAppVersions.get(0));
            response.setCode(String.valueOf(0));
        }else {
            response = new ApiResponse();
            response.setCode(String.valueOf(-1));
        }

        return response;
    }


}
